<?php
namespace Admin\Controller;
use Think\Controller;
class AdminController extends CommenController {
    public function login(){
    // $verify = new \Think\Verify();
    //      }
    //       if(!$verify->check(I('post.code')))
    //       {
    //         $this->error('验证码错误','',2);die;
    //       }


    if(IS_POST){

    // $_POST['password']=md5($_POST['password']);
    // unset($_POST['code']);

    $data=$this->Model->relation(true)->where(I('post.'))->find();

       if(!empty($data)){

         $data['group_access']=explode(',',  $data['group_access'][0]['rules']);
// $this->GetLastSql();
// print_r($data);
         session('admin_user',$data);

// print_r($_SESSION);die;
      $this->success('登录成功',U('index/index'),2);die;

      }else{

       $this->error('登录失败','',2);die;
      }
}
    $this->display();

}


//  public function getCode(){
//     $Verify = new \Think\Verify();
//     $Verify->fontSize = 50;
//     $Verify->entry();

// }


function lists(){


    $admin=D('admin');

    $list = $admin->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

    $this->assign('lists',$list);






  $this->display(); // 输出模板



}

  function add(){


    $admin=D('admin');

    if(IS_POST){

      $_POST['avathor']=$this->upload();


      $id=$admin->add(I('post.'));

      if($id>0){

     $this->success('添加成功',U('admin/lists'),2);die;
// $this->GetLastSql();
        # code...
      }else{
         $this->error('添加失败','',2);die;
      }

    }

   $group = D('group')->select();
    // print_r($group);die;
    $this->assign('group',$group);
    $this->display();
}

function adxit(){
  if(IS_POST){
     $id=I('get.id');

     $data['group_id']=I('post.group_id');

     unset($_POST['group_id']);

    $this->Model->where("id=$id")->save(I('post.'));
    D('group_access')->where('uid=$id')->save($data);
  }
    $data=D('admin')->getByid(I('get.id'));
// print_r($data);die;
    $this->assign('data',$data);
    $this->display(); // 输出模板

}

function del_avathor(){

    $data=D('admin')->getByid(I('get.id'));



    $new['id']=I('get.id');
    $filed['avathor']='';

   $id=D('admin')->where($new)->save($filed);

    if ($id>0) {

      // unlink('./'.$data['avathor']);
          $this->success('删除成功',U('Admin/admin/lists'),3);die;
      # code...
    }else{
       $this->error('删除失败','',3);die;
    }


}




}
